package com.gitee.jjnnzb.designpatterninspring;

import cn.hutool.core.net.NetUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;

import java.net.InetAddress;

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class})
@Slf4j
public class DesignPatternInSpringApplication {
    
    private static String port;
    
    @Value("${server.port}")
    public void setPort(String port) {
        DesignPatternInSpringApplication.port = port;
    }
    
    public static void main(String[] args) {
        SpringApplication.run(DesignPatternInSpringApplication.class, args);
        
        InetAddress inetAddress = NetUtil.getLocalhost();
        String ip;
        if (inetAddress != null) {
            ip = inetAddress.getHostAddress();
        } else {
            ip = "localhost";
        }
        
        String url = String.format("http://%s%s%s", ip + ":", port, "/doc.html");
        if (log.isInfoEnabled()) {
            log.info("-----------------------------------------------------------------");
            log.info("##### 程序启动成功！");
            log.info("##### 点击该服务地址打开文档api文档 : {} ,仅dev 和 test 环境支持api文档", url);
            log.info("##### 数据库文档自动生成代码见test/java/com/njwx/yq/DataBasDoc main方法(根据需要自行调整数据库链接和数据库信息)");
            log.info("-----------------------------------------------------------------");
        }
    }
    
}
